/* eslint-disable @typescript-eslint/no-explicit-any */
import axios, { AxiosResponse, InternalAxiosRequestConfig } from "axios";
// import { useRouter } from "vue-router";
// const router = useRouter();
// axios.defaults.baseURL = 'api';
const service = axios.create();

// Request interceptors
service.interceptors.request.use(
  (config: InternalAxiosRequestConfig) => {
    // do something
    // const token = localStorage.getItem("token");
    // if (token) {
    //   config.headers.token = token;
    // }
    return config;
  },
  (error: any) => {
    Promise.reject(error);
  }
);

// Response interceptors
service.interceptors.response.use(
  async (response: AxiosResponse) => {
    console.log("response", response);
    return Promise.resolve(response.data);
  },
  (error: any) => {
    // do something
    console.log("error", error);
    return Promise.reject(error);
  }
);

export default service;
